/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package br.ufrj.dcc.comp2.projeto.modelos;

import java.io.File;

import javax.imageio.ImageIO;

/**
 * Classe modelo de alienigina.
 * @author Bruno(Magoo), Eluan(Acre), Diego(Silvio), Davi.
 *
 */
public class Alienigena extends Componentes {
	
	long timeToDie;
	
	public Alienigena(Vetor2D posicao, String enderecoImagem, int velocidade) {
		super(enderecoImagem);		
		this.posicao.setX(posicao.getX());
		this.posicao.setY(posicao.getY());
		this.velocidade.setY(velocidade);
		this.setMass(30);
		this.timeToDie = 0;
	}
	
	/**
	 * Define tempo at� a morte do alien.
	 * @param timeToDie
	 */
	public void setTimeToDie(long timeToDie) {
		if (this.timeToDie == 0) {
			this.timeToDie = timeToDie;
		}
	}
	
	public long getTimeToDie() {
		return this.timeToDie;
	}
	
	/**
	 * Atualiza imagem de explos�o do alien.
	 * @param enderecoImagem
	 */
	public void updateKaboomImage(String enderecoImagem){
		if(this.enderecoImagem == enderecoImagem) return;
			
		try {
			this.imagem = ImageIO.read(new File(enderecoImagem));
			this.enderecoImagem = enderecoImagem;
		} catch (Exception e) {
			System.out.println("Imagem n�o encontrada.");
		}		
	}

	/**
	 * Atualiza estado da explos�o do alien.
	 *
	 */
	public void updateKaboom(){
		if(this.timeToDie <= 900)
		{
			if(this.timeToDie >= 750) updateKaboomImage("resources/explosao/exp_01.png");
			else if(this.timeToDie >= 600) updateKaboomImage("resources/explosao/exp_02.png");
			else if(this.timeToDie >= 450) updateKaboomImage("resources/explosao/exp_03.png");
			else if(this.timeToDie >= 300) updateKaboomImage("resources/explosao/exp_04.png");
			else if(this.timeToDie >= 150) updateKaboomImage("resources/explosao/exp_05.png");
			else updateKaboomImage("resources/explosao/exp_06.png");
		}
	}
	
	/**
	 * Diminui tempo restante at� o alien morrer (sumir da tela).
	 * @param frameTime
	 * 
	 */
	public boolean subtractTimeToDie(long frameTime) {
		if (this.timeToDie > 0)	{
			this.timeToDie -= frameTime;
			if (this.timeToDie == 0) {
				this.timeToDie = -1;
			}
			if (this.timeToDie < 0) {
				return true;
			}
			return false;
		}		
		return false;
	}
}
